﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using BLL;

namespace Web.admin.CompetitionManage
{
    public partial class EditAwardLevel : System.Web.UI.Page
    {
        private AwardService awardService = new AwardService();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                string operation = Request["OPERATION"];
                if (operation == null)
                    return;
                string AwaId = Request["AWA_ID"];
                if (AwaId == null)
                    return;

                if (operation == "Modify")
                {
                    ModifyPhases(AwaId);
                }
                else if (operation == "Delete")
                {
                    DeletePhases(AwaId);
                }
            }
        }

        protected void ModifyPhases(string AwaId)
        {
            BoAwards Awards = awardService.GetAward(AwaId);
            txtAwaId.Value = Awards.AWA_ID;
            txtName.Text = Awards.AWA_NAME;
            TextType.Text = Awards.AWA_TYPE.ToString();
            leval_list.SelectedValue = Awards.AWA_LEVAL;
        }

        protected void DeletePhases(string AwaId)
        {
            BoAwards awards = new BoAwards();
            awards.AWA_ID = AwaId;
            awardService.DeleteAward(awards);
            Response.Redirect("AwardLevel.aspx");
           
        }

        protected void ButtonOK_Click(object sender, EventArgs e)
        {
            if (txtAwaId.Value == "")
            {
                BoAwards awards = new BoAwards();
                awards.AWA_NAME = txtName.Text;
                awards.AWA_TYPE = Convert.ToInt32(TextType.Text);
                awards.AWA_IsShow = bool.Parse(DropDownList1.SelectedValue);
                awards.AWA_LEVAL = leval_list.SelectedValue;
                awardService.CreateAward(awards);
                Response.Redirect("AwardLevel.aspx");
                
            }
            else
            {
                BoAwards awards=new BoAwards();
                awards.AWA_ID = txtAwaId.Value;
                awards.AWA_NAME = txtName.Text;
                awards.AWA_TYPE = Convert.ToInt32(TextType.Text);
                awards.AWA_IsShow = bool.Parse(DropDownList1.SelectedValue);
                awards.AWA_LEVAL = String.Copy(leval_list.SelectedValue);
                awardService.UpdateAward(awards);
                Response.Redirect("AwardLevel.aspx");
            
            }
        }


    }
}